#!/bin/sh
# This regression test is a part of SIPp.
# An INVITE whose SDP has no [len] (a Content-Length written out, as
# here) is an offer all the same: a UAC offering AES_256_CM then
# AES_192_CM keys sends its SRTP in the second suite the UAS answers
# with, and the UAS decrypts it. The UAS logs whether it could decrypt
# each packet it echoes.
. "`dirname "$0"`/../functions"; init

rm -f debug*file* srtpctxdebugfile*
sippbg -sf uas.xml -i 127.0.0.1 -p 26840 -m 1 -srtpcheck_debug \
    -min_rtp_port 26850 -max_rtp_port 26859 -timeout 10
sippfg -sf uac.xml -i 127.0.0.1 -p 26841 -m 1 \
    -min_rtp_port 26860 -max_rtp_port 26869 \
    127.0.0.1:26840 -timeout 10 -timeout_error >/dev/null 2>&1
status=$?
wait
decrypted=`cat debugrefile*.log 2>/dev/null | grep -c 'processIncomingPacket() rc == 0'`
rejected=`cat debugrefile*.log 2>/dev/null | grep -c 'processIncomingPacket() rc == -'`
rm -f debug*file* srtpctxdebugfile*

if test $rejected -ne 0 || test $decrypted -eq 0; then
    fail "the UAS rejected $rejected SRTP packets, decrypted $decrypted"
elif test $status -ne 0; then
    fail "UAC failed with $status"
else
    ok
fi
